package com.jsonal.controller;

import com.jsonal.service.UploadFilesService;
import com.jsonal.vo.Result;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: jsonal
 * @Description:
 * @Date: 2020/11/19 17:07
 * @Version: 1.0
 */
@Controller
public class UploadController {
    @Autowired
    private UploadFilesService uploadFilesService;

    @RequestMapping(value = "/api/carousel", method = RequestMethod.POST)
    @ResponseBody
    public Result uploadCarousel(
        HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile file) {
        String folder = request.getParameter("folder");
        String fileId = request.getParameter("fileId");
        return uploadFilesService.saveFiles(file, fileId, folder);
    }


    @RequestMapping(value = "/upload/videoUpload", method = RequestMethod.POST)
    @ResponseBody
    public Result uploadVideo(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile file) {
        String folder = request.getParameter("folder");
        String fileId = request.getParameter("fileId");
        return uploadFilesService.saveFiles(file, fileId, folder);
    }
}
